<template>
  <div>
    <!-- 用户列表信息 -->
    <el-container>
      <!--功能区域 -->
      <el-header
        style="
          padding: 0px;
          display: flex;
          justify-content: space-between;
          align-items: center;
        "
      >
        <!-- 查询功能区域 -->
        <div style="display: inline">
          <el-input
            v-model="username"
            placeholder="请输入人员姓名"
            style="width: 300px; margin: 0px; padding: 0px"
          ></el-input>
          <el-button style="margin-left: 5px" @click="select" type="primary"
            >查询</el-button
          >
        </div>
        <!-- 操作功能 -->
        <div style="margin-left: 5px; margin-right: 20px; display: inline">
          <el-button type="primary" @click="add">新增</el-button>
        </div>
      </el-header>
      <!--列表区域 -->
      <el-main style="padding-left: 0px; padding-top: 0px">
        <el-table :data="Users" border style="width: 100%">
          <el-table-column
            prop="username"
            label="登陆账号"
            width="200px"
          ></el-table-column>
          <el-table-column
            prop="password"
            label="登陆密码"
            width="190px"
          ></el-table-column>
          <el-table-column
            prop="rolename"
            label="角色"
            width="190px"
          ></el-table-column>
          <el-table-column
            prop="shuoming"
            label="说明"
            width="250px"
          ></el-table-column>
          <el-table-column label="操作" width="240px">
            <template slot-scope="scope">
              <el-button
                style="padding: 3px, 4px, 3px, 4px; margin: 2px"
                @click="update"
                >修改</el-button
              >
              <el-button
                style="padding: 3px, 4px, 3px, 4px; margin: 2px"
                @click="delUser"
                >删除</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </el-main>
    </el-container>
    <!-- 模态显示图层 -->
    <el-form :model="user" ref="userFrom" style="margin: 0px; padding: 0px">
      <div style="text-align: left">
        <el-dialog
          style="padding: 0px"
          width="25%"
          :visible.sync="dialogVisible"
        >
          <el-row>
            <el-col :span="20">
              <div>
                <el-form-item label="账号">
                  <el-input
                    v-model="user.username"
                    style="width: 200px; height: 20px"
                    placeholder="请输入账号"
                  ></el-input>
                </el-form-item>
              </div>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="20">
              <div>
                <el-form-item label="密码">
                  <el-input
                    v-model="user.password"
                    style="width: 200px; height: 20px"
                    placeholder="请输入密码"
                  ></el-input>
                </el-form-item>
              </div>
            </el-col>
          </el-row>
          <span slot="footer">
            <el-button @click="cancel">取消</el-button>
            <el-button @click="save" type="primary">保存</el-button>
          </span>
        </el-dialog>
      </div>
    </el-form>
  </div>
</template>
<script>
export default {
  name: "UserList",
  data() {
    return {
      Users: [],
      user: {
        userid: " ",
        username: " ",
        password: " ",
        rolename: " ",
        shuoming: "",
      },
      username: "",
      dialogVisible: false,
    };
  },
  created() {
    this.getJson();
  },
  methods: {
    select() {
      console.log("请入查询方法");
      console.log(this.username);
    },
    add() {
      console.log("新增功能");
      this.dialogVisible = true;
    },
    update() {
      console.log("修改方法");
    },
    delUser() {
      console.log("删除方法");
    },
    cancel() {
      console.log("取消方法");
    },
    save() {
      console.log("保存方法");
      console.log(this.user.username);
      console.log(this.user.password);
    },
    getJson() {
      var usr = "";
      this.$axios.get("static/User.json").then((res) => {
        console.log("获取表格");
        console.log(res.data);
        this.Users = res.data;
      });
    },
  },
};
</script>